package com.mz.ozy.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.activity.shop.ShopDetailActivity;
import com.mz.ozy.activity.shop.TopicListActivity;
import com.mz.ozy.bean.HomeMerBean;
import com.mz.ozy.constants.Constants;
import com.mz.ozy.utils.glideUtils.GlideUtils;
import com.mz.ozy.widget.dialog.NotVipDialog;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Created by administrator on 2018/11/21.
 */
public class HomeTopicAdapter1 extends BaseQuickAdapter<HomeMerBean.SpecialList, BaseViewHolder> {
    private Activity mActivity;
    private int ii=0;
    //private List<HomeMerBean.SpecialListBean> mData = new ArrayList();

    public HomeTopicAdapter1(Activity activity, @Nullable List<HomeMerBean.SpecialList> data) {
        super(R.layout.list_home_food1, data);
        this.mActivity=activity;
        //mData = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeMerBean.SpecialList items) {
//        RecyclerView rvOrganicFood = helper.getView(R.id.rv_organic_food1);
//        LinearLayoutManager layoutManager1 = new LinearLayoutManager(mContext);
//        layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);//把布局设为横行排列
//        rvOrganicFood.setLayoutManager(layoutManager1);
//        HomeOrganicAdapter homeOrganicAdapter = new HomeOrganicAdapter(item.getProductList());
//        rvOrganicFood.setAdapter(homeOrganicAdapter);
//        homeOrganicAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
//            @Override
//            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//                if (!Constants.isVip) {
//                    NotVipDialog dialog = new NotVipDialog(mActivity);
//                    dialog.showDialog();
//                    return;
//                }
//                final HomeMerBean.ProductListBean productListBean = (HomeMerBean.ProductListBean) adapter.getItem(position);
//                switch (view.getId()) {
//                    case R.id.ll_item_view: {
//                        Intent intent = new Intent(mContext, ShopDetailActivity.class);
//                        intent.putExtra("goodsId", productListBean.getId() + "");
//                        mContext.startActivity(intent);
//                        break;
//                    }
//                    case R.id.iv_goods_pic: {
//                        Intent intent = new Intent(mContext, ShopDetailActivity.class);
//                        intent.putExtra("goodsId", productListBean.getId() + "");
//                        intent.putExtra("show", 1);
//                        mContext.startActivity(intent);
//                        break;
//                    }
//                }
//            }
//        });
        for(int i=0;i<items.getSpecialList().size();i++) {
            HomeMerBean.SpecialListBean item = items.getSpecialList().get(i);
            if (i == 0) {
                helper.setText(R.id.tv_topic_title, item.getTitle());
                ImageView ivOrganicFood = helper.getView(R.id.iv_organic_food1);

                GlideUtils.loadRoundImg(mContext, ivOrganicFood, item.getImgPath(), R.mipmap.ozy1645066221523, 4);

                final HomeMerBean.SpecialListBean specialListBean = item;
                ivOrganicFood.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
//                        if (!Constants.isVip) {
//                            NotVipDialog dialog = new NotVipDialog(mActivity);
//                            dialog.showDialog();
//                            return;
//                        }
                        Intent intent = new Intent(mContext, TopicListActivity.class);
                        intent.putExtra("id", String.valueOf(specialListBean.getId()));
                        intent.putExtra("name", specialListBean.getTitle());
                        intent.putExtra("type", "2");
                        mContext.startActivity(intent);
                    }
                });
            }
            if (i == 1) {
                ImageView ivOrganicFood = helper.getView(R.id.iv_organic_food2);
                GlideUtils.loadRoundImg(mContext, ivOrganicFood, item.getImgPath(), R.mipmap.ozy1645066221576, 4);

                final HomeMerBean.SpecialListBean specialListBean = item;
                ivOrganicFood.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
//                        if (!Constants.isVip) {
//                            NotVipDialog dialog = new NotVipDialog(mActivity);
//                            dialog.showDialog();
//                            return;
//                        }
                        Intent intent = new Intent(mContext, TopicListActivity.class);
                        intent.putExtra("id", String.valueOf(specialListBean.getId()));
                        intent.putExtra("name", specialListBean.getTitle());
                        intent.putExtra("type", "2");
                        mContext.startActivity(intent);
                    }
                });
            }
            if (i == 2) {
                ImageView ivOrganicFood = helper.getView(R.id.iv_organic_food3);
                GlideUtils.loadRoundImg(mContext, ivOrganicFood, item.getImgPath(), R.mipmap.ozy1645066267511, 4);

                final HomeMerBean.SpecialListBean specialListBean = item;
                ivOrganicFood.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
//                        if (!Constants.isVip) {
//                            NotVipDialog dialog = new NotVipDialog(mActivity);
//                            dialog.showDialog();
//                            return;
//                        }
                        Intent intent = new Intent(mContext, TopicListActivity.class);
                        intent.putExtra("id", String.valueOf(specialListBean.getId()));
                        intent.putExtra("name", specialListBean.getTitle());
                        intent.putExtra("type", "2");
                        mContext.startActivity(intent);
                    }
                });
            }
        }
    }
}

